﻿using Ldt.DataEngine.DataFlowParse.Model;
using LdtDataEngin.ModuleDetail.AnalysisModule.CaseCauseBaseInfoExtr;
using LdtDataEngin.ModuleDetail.BaseModule;
using LdtJudge.DataEngine.Common.CommHelp;
using LdtJudge.DataEngine.Common.XmlUtility;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.DataModel.SysCommon;
using LdtJudge.DataEngine.Model.XMLConfigModel.ElmentModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace LdtDataEngin.ModuleDetail.CaseExtract
{
    /// <summary>
    /// 案件要素提取模块
    /// 输入信息：格式化后的文本内容===>DataContext.DyData_Analysis
    ///          案件要素提取的配置信息===>DataContext.DataLayerSysStores
    /// 输出信息：案件分析实体对象数据===>DataContext.DataLayerAns.AnalysisResultsDataModel
    ///          案件要素分析结果数据XML===>DataContext.DataLayerAns.AnalysisResultsXml
    /// </summary>
    public class CaseExtractionAssemble:AssermBase
    {
        public CaseExtractionAssemble(DataContext context,string moduleName)
        {
            dataContext = context;
            MoudleName = moduleName;
        }

        /// <summary>
        /// 开始提取
        /// </summary>
        public void Extrat()
        {
            CaseCauseExtract caseCauseExtract = new CaseCauseExtract(dataContext, MoudleName) { origitxt=dataContext.DataLayerAns.FengXiCanShu.Juanzongneirong};
            caseCauseExtract.CaseCauseExt();
            var configModel = dataContext.DataLayerSys.GetConfigModel(MoudleName);
            if (configModel!=null)
            {
                List<ConfigModel> configDetailList = configModel.ConfigDetail;
                var caseType = dataContext.DataLayerAns.CaseType.ToLower();
                var sourceCode = dataContext.DataLayerAns.SourceCode.ToLower();
                ConfigModel configDetail = configDetailList.FirstOrDefault(a => a.Code.ToLower()== "caseelementext");
                ConfigModel amountConfig= configDetailList.FirstOrDefault(a => a.Code.ToLower()=="amountconversion");
                dataContext.InteractiveShow.LogShow($"执行模块编号:{configDetail.Code} 执行code:{configDetail.ExecuteCode} 文件路径:{configDetail.FilePath}",LogMessageType.Info);
                configDetail = configDetailList.First();
                if (configDetail?.ExecuteType == "reg")
                {
                    ExeConfig(configDetail, MoudleName);
                }
                else if (configDetail?.ExecuteType == "dll")
                {
                    // dll类型的执行
                    ElementExtractionTexTDLL dllElement = new ElementExtractionTexTDLL(dataContext);
                    dllElement.Extract(configDetail.FilePath, this.MoudleName);
                }
                else if (configDetail?.ExecuteType == "xml")

                {
                    //配置XML的为要素分析
                    ElementExtractionTexTXml xmlElement = new ElementExtractionTexTXml(dataContext);
                    xmlElement.Extract(configDetail, MoudleName, amountConfig);
                }
                
            }
        }
    }
}